anima.define({
      
/* component descriptor */
webid: "<http://purl.org/dcc/visual.state.switch.Switch>",
superWebid: "<http://purl.org/dcc/view.base.WidgetBase>",

/* component creator */
creator: function(context, webid) {
   var constructor = function() {
      this.on = false;
      this.imgBase = context.anima.database.jslocal.resolverDirectory(webid);
      this.presentation = document.createElement("img");
      this.updatePresentation();
   };
   
   var prototype = {
     getPresentation: function() {
        return this.presentation;
     },

     setInstanceId: function(instanceId) {
        if (this.instanceId == null) {
           if (instanceId == null)
               this.instanceId = this.generateIntanceId();
           else
               this.instanceId = instanceId;
       }
        this.updatePresentation();
     },
     
     updatePresentation: function() {
        this.presentation.setAttribute("src",
              this.imgBase + ((this.on) ? "switch-on.png" : "switch-off.png"));
        if (this.getInstanceId() != null)
           this.presentation.setAttribute("onclick", "anima.composition.component('" +
                 this.getInstanceId() + "').reverse()");
     },
     
     reverse: function() {
        this.on = !this.on;
        this.updatePresentation();
     }
   };
   
   anima.component.create(context, webid, constructor, prototype);
}

});                  
